<?php
	
autoLoader();

// display( $_REQUEST );
// display( $_POST ); exit;

if( false == isset( $_POST['Submit'] ) || false == valStr( $_POST['first_name'] ) ) { 
	$str = '';
	$str .= '<form name=myform method=post action=modules.php?file=employees&mid=' . $_REQUEST['mid'] . '&smid=' . $_REQUEST['smid'] . '>';
	$str .= '<script language=JavaScript>document.myform.submit();</script></form>';
	echo $str;
	exit;
}

if( true == isset( $_POST['operation'] ) && 'insert' == strtolower( $_POST['operation'] ) ) {
$objBaseEmployees 	= new BaseEmployees();

	$objBaseEmployees->setDepartmentId( $_POST['department_id'] );
	$objBaseEmployees->setEmployeeTypeId( $_POST['employee_type_id'] );
	$objBaseEmployees->setFirstName( $_POST['first_name'] );
	$objBaseEmployees->setMiddleName( $_POST['middle_name'] );
	$objBaseEmployees->setLastName( $_POST['last_name'] );
	$objBaseEmployees->setPhoneNumber( $_POST['phone_number'] );
	$objBaseEmployees->setMobileNumber( $_POST['mobile_number'] );
	$objBaseEmployees->setOfficeNumber( $_POST['office_number'] );
	$objBaseEmployees->setEmailAddress( $_POST['email_address'] );
	$objBaseEmployees->setAddressLine1( $_POST['address_line1'] );
	$objBaseEmployees->setAddressLine2( $_POST['address_line2'] );
	$objBaseEmployees->setArea( $_POST['area'] );
	$objBaseEmployees->setCity( $_POST['city'] );
	$objBaseEmployees->setPinCode( $_POST['pin_code'] );
	
	$objBaseEmployees->setCreatedBy( ( true == isset( $_SESSION['SESS_MEMBER_ID'] ) ) ? $_SESSION['SESS_MEMBER_ID'] : 1 );
	$objBaseEmployees->setUpdatedBy( ( true == isset( $_SESSION['SESS_MEMBER_ID'] ) ) ? $_SESSION['SESS_MEMBER_ID'] : 1 );
	$objBaseEmployees->setUpdatedOn( 'now()' );
	
	if( 1 == $objBaseEmployees->insert() ) {
		$str = '';
		$str .= '<form name=myform method=post action=modules.php?file=view_employees&type=view&mid=' . $_REQUEST['mid'] . '&smid=' . $_REQUEST['smid'] . '>';
		$str .= '<script language=JavaScript>document.myform.submit();</script></form>';
		echo $str;
		exit;
	}
} else if( true == isset( $_POST['operation'] ) && 'update' == strtolower( $_POST['operation'] ) ) {

	$objEmployees 	= new Employees();
	$objBaseEmployees 	= $objEmployees->fetchEmployeesById( $_POST['employee_id'] );
	
    $objBaseEmployees->setDepartmentId( $_POST['department_id'] );
	$objBaseEmployees->setEmployeeTypeId( $_POST['employee_type_id'] );
	$objBaseEmployees->setFirstName( $_POST['first_name'] );
	$objBaseEmployees->setMiddleName( $_POST['middle_name'] );
	$objBaseEmployees->setLastName( $_POST['last_name'] );
	$objBaseEmployees->setPhoneNumber( $_POST['phone_number'] );
	$objBaseEmployees->setMobileNumber( $_POST['mobile_number'] );
	$objBaseEmployees->setOfficeNumber( $_POST['office_number'] );
	$objBaseEmployees->setEmailAddress( $_POST['email_address'] );
	$objBaseEmployees->setAddressLine1( $_POST['address_line1'] );
	$objBaseEmployees->setAddressLine2( $_POST['address_line2'] );
	$objBaseEmployees->setArea( $_POST['area'] );
	$objBaseEmployees->setCity( $_POST['city'] );
	$objBaseEmployees->setPinCode( $_POST['pin_code'] );
	
	$objBaseEmployees->setCreatedBy( ( true == isset( $_SESSION['SESS_MEMBER_ID'] ) ) ? $_SESSION['SESS_MEMBER_ID'] : 1 );
	$objBaseEmployees->setUpdatedBy( ( true == isset( $_SESSION['SESS_MEMBER_ID'] ) ) ? $_SESSION['SESS_MEMBER_ID'] : 1 );
	$objBaseEmployees->setUpdatedOn( 'now()' );
	
	if( 1 == $objBaseEmployees->update() ) {
		$str = '';
		$str .= '<form name=myform method=post action=modules.php?file=view_employees&type=view&mid=' . $_REQUEST['mid'] . '&smid=' . $_REQUEST['smid'] . '>';
		$str .= '<script language=JavaScript>document.myform.submit();</script></form>';
		echo $str;
		exit;
	}
}

?>